<?php
namespace app\supermanager\controller;
use app\common\traits\controller\TraitController;
class Caravan extends \think\Controller
{
	use TraitController;
	public function init(){
		if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
	    $this->model = model('Caravans');
		$this->list_route = url('/caravans');
	}

    /**
     * GET shwo caravan info list
     * @return [type] [description]
     */
    public function index()
    {	//分公司
		$branchs = model('Filiales')->column('name','id');
        $this->assign('branchs',$branchs);
        $list = model('Caravans')->getCaravansLists(input('get.'));
        $this->assign('list',$list);
        return view('caravan/index');
    }
	
	/**
	 * 查看资源详情
	 */
	public function read($id){
		$ziduans = $this->model->getZiduna();
		$this->assign('ziduans',$ziduans);
		$this->assign('speed',$this->model->speed());
		$this->assign('driverType',$this->model->driverType());
		$list = $this->model->where('id',$id)->find();
	    //获取当前房车所在某时间段的状态---》如分享、托管
		$caravanStatus = model('User/Calendar')->getCaravanStatus($id);
		$rentPriceArray = model('User/Calendar')->where('caravan_id',$id)->where('rents','1')->column('single_day_price', 'datetimes');
	    return view('caravan/read',[
		    'list'=>$list,
		    'share'=>$caravanStatus['shares'],
		    'disables'=>$caravanStatus['disables'],
		    'rents'=>$caravanStatus['rents'],
		    'rentPriceArray'=>json_encode($rentPriceArray)
	    ]);
	}
	
	/**
	 * 设置首页热门
	 */
	public function setHot($id,$hot){
		if($this->model->where('hot',1)->count('hot')===10){
			$this->success('首页热门数量已满10个');
		}
		if($this->model->where(['id'=>$id])->update(['hot'=>$hot])===1){
			$this->success('设置成功',$this->list_route);
		}
		$this->error('设置失败');
	}
	
}

